using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using DG.Tweening;

namespace Main.Light
{
    public class LightControl : MonoBehaviour
    {
        public LightPattenList_SO LightData;
        public Light2D currentLight;
        public LightDetails currentLightDetails;

        internal void ChangeLight(Season currentSeason, LightShift lightShift, float timeDifference)
        {
            if (LightData.TryGetLightDetails(currentSeason, lightShift, out currentLightDetails))
            {
                if (timeDifference < Settings.lightChangeDuration)
                {
                    var colorOffset = (currentLightDetails.lightColor - currentLight.color) / Settings.lightChangeDuration * timeDifference;
                    currentLight.color += colorOffset;

                    DOTween.To(() => currentLight.color, c => currentLight.color = c, currentLightDetails.lightColor, Settings.lightChangeDuration - timeDifference);
                    DOTween.To(() => currentLight.intensity, i => currentLight.intensity = i, currentLightDetails.lightAmount, Settings.lightChangeDuration - timeDifference);
                }

                if (timeDifference >= Settings.lightChangeDuration)
                {
                    currentLight.color = currentLightDetails.lightColor;
                    currentLight.intensity = currentLightDetails.lightAmount;
                }
            }

        }
    }
}
